﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace ZG_member
{
    public partial class Discount : Form
    {
        public Discount()
        {
            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
        }

        private void Discount_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
            DGV();
        }
        public void DGV()
        {
            ZG_member.BLL.goodsInfo goods = new ZG_member.BLL.goodsInfo();
            DataTable dt= goods.GetAll("").Tables[0];
            dataGridView1.DataSource = dt;
            ZG_member.BLL.goods good = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodMode = new ZG_member.Model.goods();
            if (dataGridView1.Rows.Count != 0)
            {
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    string gid = item.Cells["gid"].Value.ToString();
                    goodMode=  good.getModelGoodsIdString(gid);
                    item.Cells["goodsName"].Value = goodMode.goodsName;
                }
            }
        }
        //15010086079

        private void button1_Click(object sender, EventArgs e)
        {
            ZG_member.BLL.goodsInfo goods = new ZG_member.BLL.goodsInfo();
            string beginTime=this.dateTimePicker1.Value.ToString();
            string endTime=this.dateTimePicker3.Value.ToString();
            decimal start = Convert.ToDecimal(this.textBox1.Text);
            decimal end = Convert.ToDecimal(this.textBox2.Text);
           
            decimal a;
            if (end < start)
            {
                a = start;
                start = end;
                end = a;
            }
            dataGridView1.DataSource = goods.GetAll("selltime>='" + beginTime + "' and selltime<='" + endTime+"' and zhekou>="+start+" and zhekou<="+end+" ").Tables[0];
            ZG_member.BLL.goods good = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodMode = new ZG_member.Model.goods();
            if (dataGridView1.Rows.Count != 0)
            {
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    string gid = item.Cells["gid"].Value.ToString();
                    goodMode = good.getModelGoodsIdString(gid);
                    item.Cells["goodsName"].Value = goodMode.goodsName;

                }
            }
        }

        private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            ZG_member.BLL.goods good = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodMode = new ZG_member.Model.goods();
            if (dataGridView1.Rows.Count != 0)
            {
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    string gid = item.Cells["gid"].Value.ToString();
                    goodMode = good.getModelGoodsIdString(gid);
                    item.Cells["goodsName"].Value = goodMode.goodsName;

                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }


        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }
        int flag = 0;

        private void Discount_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }
    }
}
